﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Buffalo.Lib.Common" %>
<%@ Import Namespace="Buffalo.SMECommon.DAL.Models" %>
<%@ Import Namespace="Buffalo.SMECommon.DAL" %>
<%@ Import Namespace="Buffalo.SMECommon.Enum" %>
<%@ Import Namespace="Buffalo.Web.Areas.SMECommon" %>
 

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string IDContract = Util.ToSafeString(ViewData["IDContract"]);
            ContractDAL contractDAL = new ContractDAL();

            ContractProgress contractProgress = contractDAL.GetContract(IDContract);
            string mainFolder = string.Format(@"{0}\Buffalo\Buffalo.UI.Human", Server.MapPath(@".\"));
            string wordTemplateFile = string.Empty;
            string wordFullFile = string.Empty;
            switch( (enuContractType) contractProgress.ContractType)
            {
                case enuContractType.WorkingContract:
                    wordTemplateFile = mainFolder + @"\Template\WorkingContract.xml";
                    wordFullFile = contractDAL.ExportWorkingContract(mainFolder, wordTemplateFile, IDContract);
                    break;
                case enuContractType.ByProjectContract:
                    wordTemplateFile = mainFolder + @"\Template\ByProjectContract.xml";
                    wordFullFile = contractDAL.ExportByProjectContract(mainFolder, wordTemplateFile, IDContract);
                    break;
                case enuContractType.ProfessionalContract:
                    wordTemplateFile = mainFolder + @"\Template\ProfessionContract.xml";
                    wordFullFile = contractDAL.ExportProfessionContract(mainFolder, wordTemplateFile, IDContract);
                    break;
                case enuContractType.LaborContract:
                    wordTemplateFile = mainFolder + @"\Template\LaborContract.xml";
                    wordFullFile = contractDAL.ExportLaborContract(mainFolder, wordTemplateFile, IDContract);
                    break;                
            }
            if (!string.IsNullOrEmpty(wordFullFile))
            {
                lnkOutput.Text = "Output";

                string wordFile = Path.GetFileName(wordFullFile);
                lnkOutput.NavigateUrl = @"~\Areas\SMECommon\Temp\" + wordFile;
            }
        }
    }
</script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <ext:Viewport ID="mainViewPort" runat="server" Layout="fit">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Border="false" Layout="fit">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnClose" runat="server" Text="Close" Icon="DoorOut">
                                <Listeners>
                                    <Click Handler="parent.ExportContractWindow.hide();" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:TabPanel ID="TourTabPanel" runat="server" Border="false" LayoutOnTabChange="true">
                        <Items>
                            <ext:Panel ID="panExportContract" runat="server" Title="Export excel" Padding="6" Layout="fit">
                                <Items>
                                    <ext:FormPanel ID="ExportContractForm" runat="server" Border="false" >
                                        <Items>
                                            <ext:Container ID="Container1" runat="server" Flex="1">
                                                <Items>
                                                    <ext:HyperLink ID="lnkOutput" runat="server" FieldLabel ="Output: " />
                                                </Items>
                                            </ext:Container>
                                        </Items>
                                    </ext:FormPanel>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:TabPanel>
                </Items>
            </ext:Panel>

        </Items>

    </ext:Viewport>
</body>
</html>

